import { useGetSystemPlatform, useGetWChartEnv } from "@/utils";
/**
 * @description 发布上线时无需再手动切换域名，代码会根据运行时环境自动匹配符合当前运行环境的域名
 * @author 花东红
 * @time 2025/8/7
 */
const { platform } = useGetSystemPlatform();

// 微信小程序
const WChartMiniProgramsApi: Config.WChartMiniProgramsApiType = {
  // 开发版
  develop: {
    baseUrl: "https://user-test.hmbuy.com"
  },
  // 体验版
  trial: {
    baseUrl: "https://user-test.hmbuy.com"
  },
  // 正式版
  release: {
    baseUrl: "https://user-pro.hmbuy.com"
  }
};

// H5
const H5Api: Config.H5ApiType = {
  development: {
    baseUrl: "https://user-test.hmbuy.com"
  },
  production: {
    baseUrl: "https://user-pro.hmbuy.com"
  }
};

const matchPlatformApi: Config.MatchPlatformApiType = {
  "mp-weixin": () => WChartMiniProgramsApi[useGetWChartEnv()],
  "web": () => H5Api[import.meta.env.MODE as Config.H5Env],
  "other": () => WChartMiniProgramsApi.develop || H5Api.development
};

export const BASE_URL = matchPlatformApi[platform]!().baseUrl || matchPlatformApi.other!().baseUrl;
